#ifndef SELECTIONWIDGET_H
#define SELECTIONWIDGET_H

#include <QObject>
#include <QWidget>
#include <QPropertyAnimation>
#include <QPainter>

class SelectionWidget : public QWidget
{
    Q_OBJECT
public:

    enum SideType {     //选框的不同侧边或角
        TOPLEFT_SIDE,
        BOTTONLEFT_SIDE,
        TOPRIGHT_SIDE,
        BOTTONRIGHT_SIDE,
        TOP_SIDE,
        BOTTON_SIDE,
        RIGHT_SIDE,
        LEFT_SIDE,
        NO_SIDE,
    };

    explicit SelectionWidget(const QColor &c, QWidget *parent = nullptr);

    SideType getMouseSide(const QPoint &point) const;   //获取鼠标在选框的位置
    bool getSelectionChanged();                         //获取属性-选框改变
    void setSelectionChanged(bool ischanged);           //设置属性-选框改变
    void saveGeometry();                                //保存选框
    QRect savedGeometry();                              //获取已保存选框
    QVector<QRect> handlerAreas();                      //获取需要处理的手柄区域


signals:
    void animationEnded();

protected:
    void paintEvent(QPaintEvent *);
    void resizeEvent(QResizeEvent *);
    void moveEvent(QMoveEvent *);

private:
    void updateAreas(); //更新选框

    QColor m_color;
    QPropertyAnimation *m_animation;
    QPoint m_areaOffset;
    QPoint m_handleOffset;
    QRect m_geometryBackup;

    QRect m_TLHandle, m_TRHandle, m_BLHandle, m_BRHandle; //可拖动拉伸选框的手柄 - 四角
    QRect m_LHandle, m_THandle, m_RHandle, m_BHandle;

    QRect m_TLArea, m_TRArea, m_BLArea, m_BRArea; //选框周围的阴影 - 四角
    QRect m_LArea, m_TArea, m_RArea, m_BArea;

    bool selectionChanged = false; //选框大小改变  -- 应该定义 geometry 改变

};

#endif // SELECTIONWIDGET_H
